//
//  HRFunChatViewModel.m
//  Hear
//
//  Created by mac on 2017/8/4.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRFunChatViewModel.h"
#import "HRFunChatModel.h"
#import "HRFunChatFrameModel.h"
#import "HRTopicListLayout.h"
@implementation HRFunChatViewModel

-(void)getTopicsContent:(NSDictionary *)requstDict contentArr:(void(^)(NSMutableArray *contentArr))contentArr{
    YTKApi *api = [YTKApi apiGetWithUrl:@"App/Get_GetTopics" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            
            // BodyContent
            
            
            NSArray *resultArr = [NSArray modelArrayWithClass:[HRFunChatModel class] json:dict[@"BodyContent"]];
            
            NSMutableArray *frameArr = [NSMutableArray array];
            for (HRFunChatModel *model in resultArr) {
                HRFunChatFrameModel *frameModel = [HRFunChatFrameModel new];
                frameModel.funModel = model;
                [frameArr addObject:frameModel];
            }

            
            contentArr(frameArr);
            
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            contentArr(@[]);
        }];
    }];
}

-(void)getUserTopicList:(NSDictionary *)requstDict contentArr:(void(^)(NSMutableArray *contentArr))contentArr{
    YTKApi *api = [YTKApi apiGetWithUrl:@"UserInfo/Get_GetUserTopicList" para:requstDict];
    api.cacheTime = 1;
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            
            // BodyContent
            
            
            NSArray *resultArr = [NSArray modelArrayWithClass:[HRFunChatModel class] json:dict[@"BodyContent"]];
            
            contentArr(resultArr);
            
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            contentArr(@[]);
        }];
    }];
}


-(void)getMyUserTopicList:(NSDictionary *)requstDict contentArr:(void(^)(NSMutableArray *contentArr))contentArr{
    YTKApi *api = [YTKApi apiGetWithUrl:@"UserInfo/Get_GetMyUserTopicList" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            
            // BodyContent
            NSArray *arr = [NSArray modelArrayWithClass:[HRFunChatModel class] json:dict[@"BodyContent"]];
            NSMutableArray *conArr = [NSMutableArray array];
            for (HRFunChatModel *chatModel in arr) {
                HRTopicListLayout *layoutArr = [HRTopicListLayout new];
                layoutArr.chatModel = chatModel;
                [conArr addObject:layoutArr];
            }
            if (conArr.count){
                contentArr(conArr);
            }
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            contentArr(@[]);
        }];
    }];
}
@end
